#include "Timer.h"
#include <windows.h>


Timer::Timer()
{
	mQPFTicksPerSec = 0;
	mLastElapsedTime = 0;

    // Use QueryPerformanceFrequency to get the frequency of the counter
    LARGE_INTEGER qwTicksPerSec = { 0 };
    QueryPerformanceFrequency( &qwTicksPerSec );
    mQPFTicksPerSec = qwTicksPerSec.QuadPart;

	GetElapsedTime();
}

float Timer::GetElapsedTime()
{
	LARGE_INTEGER qwTime;
	QueryPerformanceCounter( &qwTime );

	double fElapsedTime = ( float )( ( double )( qwTime.QuadPart - mLastElapsedTime ) / ( double )
                                     mQPFTicksPerSec);

	mLastElapsedTime = qwTime.QuadPart;

    if( fElapsedTime < 0.0f )
        fElapsedTime = 0.0f;

	return (float)fElapsedTime;
}

double Timer::GetAbsoluteTime()
{
    LARGE_INTEGER qwTime = { 0 };
    QueryPerformanceCounter( &qwTime );
    double fTime = qwTime.QuadPart / ( double )mQPFTicksPerSec;
    return fTime;
}